/*********************************************************************************
  *FileName:  nsuc16xx_dwdg.c
  *Version:   V1.0
  *Date:      2024-03-22
****************************************Includes***********************************/
#include "nsuc16xx_dwdg.h"


/***************************************Variables***********************************/



/***************************************Functions***********************************/

/**
  * @brief  Disable DWDG.
  * @param  None
  * @retval None
  */
void DWDG_Disable(void)
{
    SYSCTRL->SYSCFR_b.DWDGEN = 0x00;
}

/**
  * @brief  Enables DWDG.                  
  * @param  None
  * @retval None
  */
void DWDG_Enable(void)
{
    SYSCTRL->SYSCFR_b.DWDGEN = 0x0A;
}

/**
  * @brief  Write 0xAAAA to the DWDG Key Register and reload the counter.
  * @param  None
  * @retval None
  */
void DWDG_SetReloadKey(void)
{
    DWDG->DWKR_b.KEY = DWDG_RELOAD_KEY;
}

/**
  * @brief  Sets the DWDG Prescaler.
  * @param  DWDG_Prescaler: specifies the DWDG Prescaler.
  *   This parameter can be one of the following values:
  *     @arg DWDG_Prescaler_4: DWDG counter clock = SYSTEM_CLOCK/4
  *     @arg DWDG_Prescaler_8: DWDG counter clock = SYSTEM_CLOCK/8
  *     @arg DWDG_Prescaler_16: DWDG counter clock = SYSTEM_CLOCK/16
  *     @arg DWDG_Prescaler_32: DWDG counter clock = SYSTEM_CLOCK/32
  *     @arg DWDG_Prescaler_64: DWDG counter clock = SYSTEM_CLOCK/64
  *     @arg DWDG_Prescaler_128: DWDG counter clock = SYSTEM_CLOCK/128
  *     @arg DWDG_Prescaler_256: DWDG counter clock = SYSTEM_CLOCK/256
  *     @arg DWDG_Prescaler_512: DWDG counter clock = SYSTEM_CLOCK/512
  * @retval None
  */
void DWDG_SetPrescaler(uint8_t DWDG_Prescaler)
{
    DWDG->DWPR_b.PREDIV = DWDG_Prescaler;
}

/**
  * @brief  Set the DWDG Reload value.
  * @param  value: specifies the DWDG Reload value.
  * @retval None
  */
void DWDG_SetReloadValue(uint16_t value)
{
    DWDG->DWRR_b.RELOAD = value;
}

/**
  * @brief  Get the DWDG counter.
  * @param  None
  * @retval None
  */
uint16_t DWDG_GetCounter(void)
{
    return (uint16_t)DWDG->DCCR_b.PS;
}

/***************************************END OF FILE*********************************/
